using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using Newtonsoft.Json;
using NEM.Networking_Classes;
using System.Windows.Forms;


namespace NEM
{
    [Serializable]
    public class ProxyInfo
    {

        #region Private Variables / Constants
        
        #endregion

        #region Constructors
        public ProxyInfo()
        {

        }
        #endregion

        #region Properties

        #region Hidden Properties
        private bool _NewProxy = false;
        [Browsable(false)]
        public bool NewProxyInfo
        {
            get { return _NewProxy; }
            set
            {
                _NewProxy = value;

                if (value)
                {
                    _CreationDate = DateTime.Now;
                }
            }
        }
        #endregion end Hidden Properies

        #region Proxy Address Info


        private bool _EnableProxy = false;
        [Category("1 - Proxy Information")]
        [DisplayName("3 -Enable Proxy")]
        [Description("Should this proxy settings be enabled.")]
        public bool EnableProxy
        {
            get { return _EnableProxy; }
            set { _EnableProxy = value; }
        }

        private string _ProxyAddress = string.Empty;
        [Category("1 - Proxy Information")]
        [DisplayName("4 - Proxy Address")]
        [Description("IP Address for the Proxy.")]
        public string IPAddress
        {
            get { return _ProxyAddress; }
            set { _ProxyAddress = value; }
        }

        private int _ProxyPort = 0;
        [Category("1 - Proxy Information")]
        [DisplayName("5 - Proxy Address Port")]
        [Description("Port of the Proxy Address.")]
        public int Port
        {
            get { return _ProxyPort; }
            set { _ProxyPort = value; }
        }

        private DateTime _CreationDate = new DateTime();
        [Browsable(false)]
        [Category("1 - Proxy Information")]
        [DisplayName("Creation Date")]
        [Description("Date when this settings was created.")]
        public DateTime CreationDate
        {
            get { return _CreationDate; }
        }

        private Guid _ID = Guid.NewGuid();
        [Category("1 - Proxy Information")]
        [DisplayName("ID")]
        [Description("ID of this Proxy Setting")]
        [Browsable(false)]
        public Guid ID
        {
            get { return _ID; }
        }

        #endregion Proxy Address Info

        #endregion End Properties

        #region Methods

        internal bool Validate(out string pRetrunMessage)
        {
            bool lvResult = true;
            string lvReturnMessage = string.Empty;

            if (EnableProxy)
            {
                if ((IPAddress == string.Empty) || (Port == 0) || !Globals.isVlaidIP(IPAddress))
                {
                    lvResult = false;
                    lvReturnMessage = "Please Check the Proxy information as it does not pass validation.";
                }
            }

            pRetrunMessage = lvReturnMessage;
            return lvResult;
        }

        #endregion

        #region Events
        
        #endregion 

        #region Overrides
        public override string ToString()
        {
            return  "Setup Proxy";
        }
        #endregion


    }
}
